package cn.wolfcode.trip.core.service.impl;

import cn.wolfcode.trip.core.domain.Strategy;
import cn.wolfcode.trip.core.mapper.StrategyMapper;
import cn.wolfcode.trip.core.query.QueryObject;
import cn.wolfcode.trip.core.service.IStrategyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyServiceImpl implements IStrategyService {

    @Autowired
    private StrategyMapper strategyMapper;

    public void saveOrUpdate(Strategy strategy) {
        if(strategy.getId()!=null){
            strategyMapper.updateByPrimaryKey(strategy);
        }else{
            strategyMapper.insert(strategy);
        }
    }

    public List<Strategy> listAll() {
        return strategyMapper.selectAll();
    }

    public Strategy getById(Long id) {

        return strategyMapper.selectByPrimaryKey(id);
    }


    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = strategyMapper.selectForList(qo);
        return new PageInfo(list);
    }

}
